package util;

//FIXME Test cases have to be implemented!

/**
 * TimeConversion offers a static method which converts a time in milliseconds
 * from 1 jan 1970 to a formatted string in the HH.MM.SS format.
 * 
 * @author team07
 */
public class TimeConversion {

	/**
	 * Convert the time from milliseconds to Hours.Minutes.Seconds
	 * 
	 * @param millis
	 *            The milliseconds that will be converted
	 */
	public static String millisToHHMMss(long millis) {
		if (millis < 0)
			return "";
		String HH = String.valueOf(millis / 1000 / 60 / 60 % 24);
		String MM = String.valueOf(millis / 1000 / 60 % 60);
		String ss = String.valueOf(millis / 1000 % 60);
		HH = (HH.length() == 1 ? "0" + HH : HH);
		MM = (MM.length() == 1 ? "0" + MM : MM);
		ss = (ss.length() == 1 ? "0" + ss : ss);
		return HH + "." + MM + "." + ss;
	}

	/**
	 * Convert the time from milliseconds to Hours.Minutes.Seconds
	 * 
	 * @param time
	 *            The milliseconds that will be converted
	 */
	public static long hhmmssTomillis(String time) throws NumberFormatException {

		String[] splittedDate = time.split("\\.");

		int h = Integer.parseInt(splittedDate[0]);
		int m = Integer.parseInt(splittedDate[1]);
		int s = Integer.parseInt(splittedDate[2]);

		return s * 1000 + m * 1000 * 60 + h * 1000 * 60 * 60;
	}
}
